﻿<?php 
session_start();
if(isset($_SESSION['name']) && !empty($_SESSION['name']) && isset($_SESSION['user_role']) && $_SESSION['user_role']==1)
	header("Location: dashboard.php");
if(isset($_SESSION['name']) && !empty($_SESSION['name']) && isset($_SESSION['user_role']) && $_SESSION['user_role']==2) 
	header("Location: test.php?error=invalid-access");
?>

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8"> 
		<title>Smartek online test | Login</title>
		<link rel="SHORTCUT ICON" href="img/disp/favicon.png" />	
		<link rel="stylesheet" href="css/bootstrap.css"  type="text/css"/>
		<SCRIPT type="text/javascript">
    window.history.forward();
    function noBack() { window.history.forward(); }
</SCRIPT>
	</head>
	<BODY onload="noBack();"
    onpageshow="if (event.persisted) noBack();" onunload="">
		<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
		<script src="js/bootstrap.js"></script>
		
		<div class="container">
			<a href="index.php"><img src="img/disp/logo.png" alt=""></a>
		</div>		
		
		<div class="container">
			<div class="row pull-right">
				<div class="span4 pull-right" >
					<div class="pull-right">
						<?php 
						if(!isset($_SESSION['name']) || empty($_SESSION['name'])) echo  "<a href='index.php'>Register</a>";
						if(isset($_SESSION['name']) && !empty($_SESSION['name']) && isset($_SESSION['user_role']) && $_SESSION['user_role']==1) echo  "Welcome ".$_SESSION['name']."! | <a href='dashboard.php'>Dashboard</a>"; 
						if(isset($_SESSION['name']) && !empty($_SESSION['name']) && isset($_SESSION['user_role']) && $_SESSION['user_role']==2) echo  "Welcome ".$_SESSION['name']."! | <a href='test.php'>Continue test</a>"; 
						?>
					</div>
				</div>
			</div>
		</div>
		
		<div class="container">
			<hr class="featurette-divider">
		</div>
		
		
		
		
		<div class="container">
			<div class="row">
				<div class="span12" > <!--pagination-centered-->
					<?php
						if(isset($_GET['isEmailSuccess']) && $_GET['isEmailSuccess']=="yes")
							{
					?>
							Email is Successfully sent to <b><?php if(isset($_GET['email'])){ echo $_GET['email'];} ?>. </b><a href="login.php">Click Here </a> for login.<br/>
					<?php
							}
						else
							{							
					?>						
					<form method="post" action="process/login.php">
						<h4>Please enter your login details to continue</h2>
						<?php
							if(isset($_GET['error']) && $_GET['error']==1)
								{
								echo "<font color='red'>Please enter a valid Username / Password<br/></font>";
								}
						?>
						
						</br>										
							<div class="container">
								<div class="row">
									<div class="span2">Email</div>
									<div class="span9"><input type="text" name="email" value="<?php if(isset($_GET['email'])){echo $_GET['email'];} ?>">
										<span class="error">
											<?php 
												if(isset($_GET['isFound']) && $_GET['isFound']=="no") 
													{
														echo "&nbsp;&nbsp;&nbsp; Please enter a registered email. <a href='index.php?newEmail=$_GET[email]'>Click here</a> for registration.";
													}
											?>									
										</span>
									</div>										
								</div>
							</div>
							<div class="container">
								<div class="row">
									<div class="span2">Password:</div>
									<div class="span9"><input type="password" name="password" value=""><span class="error"></span></div>										
								</div>
							</div>
							<div class="container">
								<div class="row">
									<div class="span2"></div>
									<div class="span9"><!--Forgot password? <a href="forgot-password.php">Click here to reset</a>--></div>										
								</div>
							</div>
					   <input type="submit" class="btn" name="submit" value="Login">
					</form>
				</div>
			</div>
		</div>
		
		<?php
					}
		?>
		
		<div class="container marketing">
      <!-- FOOTER -->
		<div class="container">
			<hr class="featurette-divider">
		</div>
      <footer>
        <p>&copy; 2014 SCS &middot; </p>
      </footer>

    </div><!-- /.container -->
	</body>
</html>